package god.dream.notice.service;

import god.dream.notice.dao.NoticeDAO;
import god.dream.notice.model.Notice;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

public class NoticeServiceImpl implements NoticeService {
	
	
	private NoticeDAO noticeDAO;
	
	public int addNotice(Notice notice) {
		getToday(notice);
		return noticeDAO.insert(notice);
	}

	public Notice findNotice(int id) {
		return noticeDAO.findNotice(id);
	}

	public List<Notice> findNoticeList() {
		return noticeDAO.findNoticeList();
	}

	public int removeNotice(final int id) {
		return noticeDAO.delete(id);					
	}
	
	public int updateNotice(Notice notice) {
		getToday(notice);
		return noticeDAO.update(notice);
	}

	private void getToday(Notice notice) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		String today = sdf.format(cal.getTime());
		notice.setDate(today);
	}

	public NoticeDAO getNoticeDAO() {
		return noticeDAO;
	}

	public void setNoticeDAO(NoticeDAO noticeDAO) {
		this.noticeDAO = noticeDAO;
	}




}
